package com.lujieni.springbootwebsocket.service;

import com.lujieni.springbootwebsocket.dto.WebsiteMsgDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WebsiteMsgSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    
    /**
     * @Description: 发送扣费消息,无延时直接发送
     * @param
     * @return: 
     * @Author: lujieni
     * @Date: 2021/3/25
     */
    public void sendMsg(WebsiteMsgDTO websiteMsgDTO) {
        try {
            rabbitTemplate.convertAndSend("websocket-fanout-exchange", null, websiteMsgDTO);
        } catch (Exception e) {
            /*
                如果mq没有启动或者密码输错都会进入这个异常
                但routingKey输错或者exchangeName没找到不会进入
             */
           e.printStackTrace();
        }

    }

}
